# Makefile gnome-pulse-applet
#
# Copyright (C) 2009  Harry Karvonen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Author: Harry Karvonen <harry.karvonen@gmail.com>
#

DESTDIR =
LIBDIR = $(if $(findstring $(shell uname -m),x86_64),/usr/lib64,/usr/lib)
PYTHON_VERSION = $(shell python -c 'import sys; print "." . join (["%s" % (a) for a in sys.version_info[:2]])')

#.PHONY: print-%

print-%: VAR=$(@:print-%=%)

print-%:
	@echo '$(VAR) = `$($(VAR))´'

# Default target
# make
all:
	$(MAKE) -C GnomePulseAppletInterface/ \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	$(MAKE) -C locale/

# Install target
install: install-pulse-applet
	$(MAKE) -C GnomePulseAppletInterface/ install \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	$(MAKE) -C locale/ install

install-pulse-applet: install-icons
	mkdir -p $(DESTDIR)/usr/share/gnome-pulse-applet
	install -D gnome-pulse-applet.xml \
          $(DESTDIR)/usr/share/gnome-pulse-applet/gnome-pulse-applet.xml
	install -D pulse-applet.py \
          $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/site-packages/pulse-applet.py
	mkdir -p $(DESTDIR)/usr/bin/
	ln -s $(LIBDIR)/python$(PYTHON_VERSION)/site-packages/pulse-applet.py \
          $(DESTDIR)/usr/bin/pulse-applet.py
	install -D GNOME_PulseApplet_Factory.server \
          $(DESTDIR)$(LIBDIR)/bonobo/servers/GNOME_PulseApplet_Factory.server

install-icons:
	install -D icons/gnome-pulse-applet.png \
          $(DESTDIR)/usr/share/icons/gnome/32x32/apps/gnome-pulse-applet.png

install-devel:
	$(MAKE) -C GnomePulseAppletInterface/ install-devel \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	ln -s $(shell pwd)/pulse-applet.py \
          $(DESTDIR)/usr/bin/
	ln -s $(shell pwd)/GNOME_PulseApplet_Factory.server \
          $(DESTDIR)$(LIBDIR)/bonobo/servers/
	mkdir -p $(DESTDIR)/usr/share/gnome-pulse-applet
	ln -s $(shell pwd)/gnome-pulse-applet.xml \
          $(DESTDIR)/usr/share/gnome-pulse-applet/gnome-pulse-applet.xml
	ln -s $(shell pwd)icons/gnome-pulse-applet.png \
	  /usr/share/icons/gnome/32x32/apps/gnome-pulse-applet.png

uninstall:
	$(MAKE) -C GnomePulseAppletInterface uninstall \
          LIBDIR=$(LIBDIR) PYTHON_VERSION=$(PYTHON_VERSION)
	$(RM) $(DESTDIR)/usr/bin/pulse-applet.py*
	$(RM) $(DESTDIR)$(LIBDIR)/bonobo/servers/GNOME_PulseApplet_Factory.server
	$(RM) -r $(DESTDIR)/usr/share/gnome-pulse-applet

clean:
	$(MAKE) -C GnomePulseAppletInterface clean
	$(MAKE) -C locale clean
